<?php

declare(strict_types=1);

namespace App\Model;



/**
 * @property int $id 
 * @property string $session_id 
 * @property int $userid 
 * @property int $to_userid 
 * @property string $last_msg_id 
 * @property string $last_msg_type 
 * @property string $last_msg_data 
 * @property int $last_msg_userid 
 * @property int $last_msg_read 
 * @property int $last_msg_time 
 * @property int $unread 
 * @property-read null|User $user 
 */
class ImSession extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'im_session';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'session_id', 'userid', 'to_userid', 'last_msg_id', 'last_msg_type', 'last_msg_data', 'last_msg_userid', 'last_msg_read', 'last_msg_time', 'unread'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'to_userid' => 'integer', 'last_msg_userid' => 'integer', 'last_msg_read' => 'integer', 'last_msg_time' => 'integer', 'unread' => 'integer'];

    public function user(){
        return $this->hasOne(User::class, 'id', 'to_userid')->select(['id', 'nickname', 'avatar', 'role_id', 'username']);
    }
}
